package com.simple.datax.transform;

import com.simple.datax.SimpleObject;
import com.simple.datax.api.TransformerException;

/** 
 * @Title: SimpleTransformer.java 
 * @Package com.simple.datax.transform 
 * @Description: 报文转换的接口 
 * @author Paladin Chen 
 * @date 2012-12-31 下午1:20:28 
 * @version V1.0 
 */
public interface SimpleTransformer {
	/**
     * Does this transformer allow null input?
     *
     * @return true if this transformer can accept null input
     */
    boolean isAcceptNull();
    
    /**
     * By default, Simple will throw an exception if a transformer is invoked with a source object that is not compatible
     * with the transformer. Since transformers are often chained, it is useful to be able to ignore a transformer in the
     * chain and move to the next one.
     *
     * @return true if the transformer can be ignored if the current source type is not supported, false if an exception
     *         should be throw due to an incompatible source type being passed in.
     */
    boolean isIgnoreBadInput();
    
    /**
     * Transforms the supplied data and returns the result
     *
     * @param src the data to transform
     * @return the transformed data
     * @throws TransformerException if a error occurs transforming the data or if the
     *                              expected returnClass isn't the same as the transformed data
     */
    void transform(SimpleObject src) throws TransformerException;
    
    /**
     * Transforms the supplied data and returns the result
     *
     * @param src      the data to transform
     * @param encoding the encoding to use by this transformer.  many transformations will not need encoding unless
     *                 dealing with text so you only need to use this method if yo wish to customize the encoding
     * @return the transformed data
     * @throws TransformerException if a error occurs transforming the data or if the
     *                              expected returnClass isn't the same as the transformed data
     */
    void transform(SimpleObject src, String encoding) throws TransformerException;

    /**
     * Return the encoding returned by the transformer (if any).
     */
    String getEncoding();
}
